
package com.creditratingmodule.servlet;
import com.creditratingmodule.bean.TbCreditRatingType;
import com.creditratingmodule.dao.TbCreditRatingTypeDAO;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;

public class TbCreditRatingTypeServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
        String creditRatingTypeName=request.getParameter("creditRatingTypeName");
        String creditRatingTypeMemo=request.getParameter("creditRatingTypeMemo");
            if(new TbCreditRatingTypeDAO().add(new TbCreditRatingType(creditRatingTypeName,creditRatingTypeMemo))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_CreditRatingType", "CreditRatingTypeId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int creditRatingTypeId=Integer.parseInt(request.getParameter("creditRatingTypeId"));
        String creditRatingTypeName=request.getParameter("creditRatingTypeName");
        String creditRatingTypeMemo=request.getParameter("creditRatingTypeMemo");
            if(new TbCreditRatingTypeDAO().edit(new TbCreditRatingType(creditRatingTypeId,creditRatingTypeName,creditRatingTypeMemo))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method)) goList(request, response);
        if ("listById".equals(method)) {
             request.getSession().setAttribute("tbCreditRatingType",new TbCreditRatingTypeDAO().getTbCreditRatingTypeByCreditRatingTypeId(Integer.parseInt(request.getParameter("creditRatingTypeId"))));
            response.sendRedirect("CreditratingModule/TbCreditRatingTypeOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.getSession().removeAttribute("tbCreditRatingType");
            response.sendRedirect("CreditratingModule/TbCreditRatingTypeOperate.jsp");
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbCreditRatingTypeList",new TbCreditRatingTypeDAO().getTbCreditRatingTypeAll());
        response.sendRedirect("CreditratingModule/TbCreditRatingTypeList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }
}
